package com.jeecms.wicool.manager.material.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeecms.cms.entity.main.CmsUser;
import com.jeecms.common.hibernate3.Updater;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.material.WeixinMaterialDao;
import com.jeecms.wicool.entity.material.WeixinMaterial;
import com.jeecms.wicool.entity.shops.ShopInfo;
import com.jeecms.wicool.manager.material.WeixinMaterialMng;
import com.jeecms.wicool.manager.shops.WiShopInfoMng;

@Service
@Transactional
public class WeixinMaterialMngImpl implements WeixinMaterialMng {

	private WeixinMaterialDao dao;

	@Autowired
	public void setDao(WeixinMaterialDao dao) {
		this.dao = dao;
	}

	@Transactional(readOnly = true)
	public Pagination getPage(Integer shopId, Short messageType, int pageNo,
			int pageSize,CmsUser user) {
		Pagination page = dao.getPage(shopId, messageType, pageNo, pageSize, user);
		return page;
	}

	@Override
	public WeixinMaterial findById(Integer id) {
		WeixinMaterial entity = dao.findById(id);
		return entity;
	}

	@Override
	public WeixinMaterial update(WeixinMaterial bean, Integer shopId) {
		ShopInfo shop = shopMng.findById(shopId);
		bean.setShop(shop);
		Updater<WeixinMaterial> updater = new Updater<WeixinMaterial>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}

	@Override
	public WeixinMaterial save(WeixinMaterial bean, Integer shopId) {

		ShopInfo shop = shopMng.findById(shopId);
		bean.setShop(shop);
		dao.save(bean);
		return bean;
	}

	@Override
	public WeixinMaterial deleteById(Integer id) {
		WeixinMaterial bean = dao.deleteById(id);
		return bean;
	}

	@Override
	public WeixinMaterial[] deleteByIds(Integer[] ids) {
		WeixinMaterial[] beans = new WeixinMaterial[ids.length];
		for (int i = 0, len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	@Override
	public List<WeixinMaterial> getListWeixinMaterialByShopId(Integer shopId) {
		// TODO Auto-generated method stub
		return dao.getListWeixinMaterialByShopId(shopId);
	}

	@Autowired
	private WiShopInfoMng shopMng;

}